package com.codejob.portal.web.action.index;

import java.util.List;
import java.util.Locale;

import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.codejob.portal.entity.algorithm.Problem;
import com.codejob.portal.services.impl.algorithm.ProblemManager;
import com.codejob.portal.services.intf.BusinessExcption;
import com.codejob.portal.web.BaseAction;
import com.opensymphony.xwork2.ActionContext;

@Namespace("/index")
public class IndexAction extends BaseAction {

	private String language;
    private	String country;
    
    @Autowired
	private ProblemManager problemManager;
    
    private List<Problem> problemMenuList;
	
	private static final long serialVersionUID = 6689143716167505030L;

	public String index(){
		
		return "home";
	}
	

	public String algorithm(){
		try {
			problemManager.getMenuList();
		} catch (BusinessExcption e) {
			e.printStackTrace();
		}
		return "algorithm";
	}
	
	public String algorithmMenu(){
		try {
			problemMenuList=problemManager.getMenuList();
		} catch (BusinessExcption e) {
			e.printStackTrace();
		}
		return "algorithmMenu";
	}
	
	public String setLocale(){		
		if(language.equals("en")||country.equals("US")){
			ActionContext ctx = ActionContext.getContext();
			ctx.setLocale(new Locale(language, country));
		}
		if(language.equals("zh")||country.equals("CN")){
			ActionContext ctx = ActionContext.getContext();
			ctx.setLocale(new Locale(language, country));
		}
		return "index";
	}


	public String getLanguage() {
		return language;
	}


	public void setLanguage(String language) {
		this.language = language;
	}


	public String getCountry() {
		return country;
	}


	public void setCountry(String country) {
		this.country = country;
	}


	public List<Problem> getProblemMenuList() {
		return problemMenuList;
	}


	public void setProblemMenuList(List<Problem> problemMenuList) {
		this.problemMenuList = problemMenuList;
	}
	
	
}
